# import these variables from the parent build script
import os
import sys

Import('env', 'gfxlibs', 'alllibs', 'installbindir', 'datadir', 'version', 'osspecificsrc')

################## define sources #######################
dftdsources = Split("""subsim.cpp
	ai.cpp
	airplane.cpp
	cfg.cpp
	coastmap.cpp
	condvar.cpp
	convoy.cpp
	countrycodes.cpp
	credits.cpp
	date.cpp
	daysky.cpp
	depth_charge.cpp
	event.cpp
	freeview_display.cpp
	game.cpp
	game_editor.cpp
	gun_shell.cpp
	highscorelist.cpp
	keys.cpp
	logbook.cpp
	logbook_display.cpp
	map_display.cpp
	message_queue.cpp
	music.cpp
	mutex.cpp
	network.cpp
	parser.cpp
	particle.cpp
	physics.cpp
	environment.cpp
	perlinnoise.cpp
	sea_object.cpp
	sensors.cpp
	ship.cpp
	ships_sunk_display.cpp
	sky.cpp
	moon.cpp
	stars.cpp
	sonar.cpp
	sonar_operator.cpp
	submarine.cpp
	submarine_interface.cpp
	sub_bg_display.cpp
	sub_bridge_display.cpp
	sub_captainscabin_display.cpp
	sub_control_popup.cpp
	sub_ecard_popup.cpp
	sub_damage_display.cpp
	sub_gauges_display.cpp
	sub_ghg_display.cpp
	sub_kdb_display.cpp
	sub_periscope_display.cpp
	sub_tdc_display.cpp
	sub_tdc_popup.cpp
	sub_torpedo_display.cpp
	sub_torpsetup_display.cpp
	sub_uzo_display.cpp
	tdc.cpp
	texts.cpp
	thread.cpp
	tone_reproductor.cpp
	torpedo.cpp
	torpedo_camera_display.cpp
	triangulate.cpp
	user_interface.cpp
	water.cpp
	water_splash.cpp""")

dftdmediasources = Split("""
	error.cpp
	framebufferobject.cpp
	font.cpp
	image.cpp
	make_mesh.cpp
	model.cpp
	shader.cpp
	system.cpp
	texture.cpp
	vertexbufferobject.cpp
	xml.cpp""")

tinyxmlsources = Split("""
	tinyxml/tinyxml.cpp
	tinyxml/tinyxmlerror.cpp
	tinyxml/tinyxmlparser.cpp""")

oglextsources = Split("""
	oglext/OglExt.cpp
	oglext/RenderingContext.cpp
	oglext/RenderingContext.hpp""")

viewmodelsources = Split("""
        viewmodel.cpp""")

# build objects for each member of osspecificsrc
osspecificsrc_obj = [env.Object(source = x) for x in osspecificsrc]

############# programs, libs, etc.
env.StaticLibrary(target = 'dftdmedia', source = dftdmediasources, LIBS = gfxlibs)
filehelper_obj = env.Object(source = 'filehelper.cpp')
widget_obj = env.Object(source = 'widget.cpp')
datadirsobj = env.StaticObject('datadirs.cpp', CPPDEFINES = [('DATADIR', '\\"' + datadir + '/\\"')])
globaldataobj = env.StaticObject('global_data.cpp', CPPDEFINES = [('VERSION', '\\"' + version + '\\"')])
frustum_obj = env.Object(source = 'frustum.cpp')
binary = env.Program(target = 'dangerdeep', source = dftdsources + filehelper_obj + widget_obj + frustum_obj + datadirsobj + globaldataobj + osspecificsrc_obj, LIBS = alllibs)
tool1 = env.Program('viewmodel', viewmodelsources + datadirsobj + filehelper_obj + widget_obj + osspecificsrc_obj, LIBS = alllibs)
tool2 = env.Program('damagemodel', ['damagemodel.cpp', datadirsobj, filehelper_obj] + osspecificsrc_obj, LIBS = alllibs)
tool3 = env.Program('crosssection', ['crosssection.cpp', datadirsobj, filehelper_obj] + osspecificsrc_obj, LIBS = alllibs)
env.StaticLibrary(target = 'oglext', source = oglextsources)
env.StaticLibrary(target = 'tinyxml', source = tinyxmlsources)
env.Default(binary)
env.Default(tool1)
env.Default(tool2)
env.Default(tool3)

test1 = env.Program('oceantest', ['oceantest.cpp'], LIBS = alllibs)
test2 = env.Program('bsplinetest', ['bspline_test.cpp'])
env.Default(test1)
env.Default(test2)

portal = env.Program('portal', ['portal.cpp', datadirsobj, filehelper_obj, frustum_obj] + osspecificsrc_obj, LIBS = alllibs)
env.Default(portal)

############ this allows to run "scons install" to install the binary
install = env.Alias('install', env.Install(installbindir, binary))
env.Depends(install, binary)
